$(function () {
    $("#jqGrid").jqGrid({
        url: '../interview/getInfoBystatus',
        datatype: "json",
		postData: {"interviewStatus":"physicalExamination"},
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', key: true, hidden: true },
			{ label: '需求编号', name: 'damandid', index: 'damandid',hidden: true },
            { label: '求职单位名称', name: 'company', index: 'company' },
            { label: '岗位名称', name: 'jobname', index: 'jobname' },
            { label: '求职人员姓名', name: 'empname', index: 'empname' },
			{ label: '性别', name: 'sex', index: 'sex',formatter:getDictInfo},
			{ label: '年龄', name: 'age', index: 'age' }, 			
			{ label: '学历', name: 'education', index: 'education', formatter: getDictInfo },
			{ label: '证书', name: 'ertificate', index: 'ertificate' }, 			
			{ label: '婚否', name: 'married', index: 'married',
                formatter:function(v){
                    if(v=="0"){
                        return "未婚";
                    }else if(v=="1"){
                        return "已婚";
                    }else if(v=="2"){
                        return "离异";
                    }else{
                        return v;
                    }
                } },
			{ label: '求职单位编号', name: 'companyid', index: 'companyid',hidden: true },
			{ label: '岗位编号', name: 'jobid', index: 'jobid',hidden: true },
			{ label: '一面状态', name: 'firInterviewStatus', index: 'fir_interview_status',hidden: true },
			{ label: '二面状态', name: 'secInterviewStatus', index: 'sec_interview_status',hidden: true },
			{ label: '体检状态', name: 'physicalExaminationStatus', index: 'physical_examination_status',
                formatter:function(v){
                    if(v=="0"){
                        return "未体检";
                    }else if(v=="1"){
                        return "通过";
                    }else if(v=="2"){
                        return "不通过";
                    }else if(v=="3"){
                        return "延时体检";
                    }else{
                        return v;
                    }
                } },
			{ label: '延迟体检时间', name: 'laterPeTime', index: 'later_pe_time'}
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        //字段太多自动加载横轴滚动条
        shrinkToFit:false,
        autoScroll: false,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
            //doResize();
            //显示grid底部滚动条
            //$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "scroll" });
        }
    });
});

//自动跳转列表宽度
/*function doResize(){
    var td=$('#tdCompute')//获取计算实际列长度的容器
        ,tds//临时保存列
        ,arr=[];//用于保存最大的列宽
    //遍历每行获得每行中的最大列宽
    $('#gview_jqGrid .ui-jqgrid-htable tr,#jqGrid tr:gt(0)').each(function(){
        $(this).find('td,th').each(function(idx){
            arr[idx]=Math.max(arr[idx]?arr[idx]:0,td.html($(this).text())[0].offsetWidth);
        })
    });
    $('#gview_jqGrid th').each(function(idx){this.style.width=arr[idx]+'px'});//设置页头单元格宽度
    $('#jqGrid tr:eq(0) td').each(function(idx){this.style.width=arr[idx]+'px'});//设置内容表格中控制单元格宽度的单元格，在第一行

    var total=$('#jqGrid').closest('.ui-jqgrid-bdiv')[0].scrollWidth;//获取表格宽度
    $('#jqGrid,#gview_jqGrid .ui-jqgrid-htable').css({width:total});//设置表头表格和内容表格宽度
    $('#gbox_jqGrid,#gview_jqGrid,#gview_jqGrid>div:gt(0)').css({width:total+15});//设置表头表格和内容表格父容器的宽度
}*/

var vm = new Vue({
	el:'#rrapp',
	data:{
        q: {
            name: null,
            unitName:null,
            psState:null
        },
		showList: true,
		title: null,
		interview: {}
	},
	methods: {
        passPS: function(){
            var ids = getSelectedRows();
            if(ids == null){
                return ;
            }
            var params = new Object();
            params.operation = "passPS";
            params.type = "ps";
            params.ids = ids;
            // params.physicalExaminationStatus = vm.interview.physicalExaminationStatus;

            $.ajax({
                type: "POST",
                url: "../interview/updateStatus",
                contentType: "application/json",
                data: JSON.stringify(params),
                success: function(r){
                    if(r.code == 0){
                        alert('操作成功', function(index){
                            $("#jqGrid").trigger("reloadGrid");
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        failedPS: function(){
            var ids = getSelectedRows();
            if(ids == null){
                return ;
            }
            var params = new Object();
            params.operation = "failedPS";
            params.type = "ps";
            params.ids = ids;
            $.ajax({
                type: "POST",
                url: "../interview/updateStatus",
                contentType: "application/json",
                data: JSON.stringify(params),
                success: function(r){
                    if(r.code == 0){
                        alert('操作成功', function(index){
                            $("#jqGrid").trigger("reloadGrid");
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        laterPS: function(){
            var ids = getSelectedRows();
            if(ids == null){
                return ;
            }
            var params = new Object();
            params.operation = "laterPS";
            params.type = "ps";
            params.ids = ids;
            $.ajax({
                type: "POST",
                url: "../interview/updateStatus",
                contentType: "application/json",
                data: JSON.stringify(params),
                success: function(r){
                    if(r.code == 0){
                        alert('操作成功', function(index){
                            $("#jqGrid").trigger("reloadGrid");
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });

        },
        laterPSView:function(){
            var ids = getSelectedRows();
            if(ids == null){
                return ;
            }

            var params = new Object();
            params.operation = "laterPS";
            params.type = "ps";
            params.ids = ids;

            layer.open({
                type: 1,
                offset: '50px',
                skin: 'layui-layer-molv',
                title: "延迟体检时间",
                area: ['300px', '200px'],
                shade: 0,
                shadeClose: false,
                content: jQuery("#popLayer"),
                btn: ['确定', '取消'],
                btn1: function (index) {
                    // console.log(vm.customVisit);
                    params.psTime = $("#psTime").val();

                    $.ajax({
                        type: "POST",
                        url: "../interview/updateStatus",
                        contentType: "application/json",
                        data: JSON.stringify(params),
                        success: function(r){
                            if(r.code == 0){
                                alert('操作成功', function(index){
                                    $("#jqGrid").trigger("reloadGrid");
                                });
                            }else{
                                alert(r.msg);
                            }
                        }
                    });


                }


            });



        },
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.interview = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.interview.id == null ? "../interview/save" : "../interview/update";
			$.ajax({
				type: "POST",
			    url: url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.interview),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../interview/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../interview/info/"+id, function(r){
                vm.interview = r.interview;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{'empname':vm.q.name ,
                         'unitName':vm.q.unitName,
                       'psState':vm.q.psState },
                page:page
            }).trigger("reloadGrid");
		}

	}
});